<?php

namespace app\api\model;

use think\Db;
use app\service\UserRepeat;

class Reg extends Common
{
    static public function parentSay($user_id, $sex, $yqr='', $parent='')
    {
        $request = request();
        $url = $request->domain() . str_replace('/index.php', '', $request->baseFile()) . '/apis/home/privatechat/addtalk';

        if ($yqr) {
            $parent = (new User)->field('id, sex')->where(['yqm' => $yqr])->find();
        }

        if ($parent && $parent['sex'] != $sex) {
            $datas = [
                'userid' => $user_id,
                'touserid' => $parent['id'],
                'type' => 0,
                'content' => '我在这儿呢',
                'system_greet' => 1,
                'timing' => 1,
                'single' => 1,
                'notice' => 1,
            ];

            curl($url, json_encode($datas, JSON_UNESCAPED_UNICODE));
        }
    }


    public static function checkDevice($device_id, $user_id)
    {
        UserRepeat::InsertS($user_id, 'device_ids', $device_id);
        $ids = Db::name('user_repeat_check')->where('find_in_set("'.$device_id.'",device_ids)')->column('user_id');
        $ban = Db::name('user')->where(['id'=>['in', $ids]])->where('find_in_set(4,danger_tags)')->column('id');
        if (sizeof($ban)) {
            Db::name('user')->where(['id'=>$user_id])->update([
                'is_banned'=>1,
                'banned_end_time'=>date("Y-m-d H:i:s",strtotime("+3 years",strtotime(date('Y-m-d')))),
                'danger_tags'=>'4'
            ]);
        }
    }
}
